#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//#include <immintrin.h>
//#include <emmintrin.h>
#define ll long long
#define ls(x) ((x)*2)
#define rs(x) ((x)*2+1)
#define fi first
#define se second
#define pii pair<int,int>
#define Debug(...) fprintf(stderr, __VA_ARGS__)
#define For(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define Rof(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
#define rep(i,  b) for(int i=1,i##end=b;i<=i##end;i++)
using namespace std;
const int N=1e6+5,base=999983,Mod=999999999;
char buf[(1<<21)+5],*p1,*p2;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline void chmx(int &x,int y){(x<y)&&(x=y);}
inline void chmn(int &x,int y){(x>y)&&(x=y);}
inline void Add(ll &x,int y){(x=(x+y>=Mod?(x+y>=2*Mod?x+y-2*Mod:x+y-Mod):x+y));}
inline int read(){
	int f=0,x=0;
	char ch=getchar();
	while(!isdigit(ch)){f|=(ch=='-');ch=getchar();}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	return f?-x:x;
}
void print(int n){
    if(n<0){
        putchar('-');
        n*=-1;
    }
    if(n>9) print(n/10);
    putchar(n%10+'0');
}
int n,Q;
ll a[4005][4005];
ll tr[4005][4005];
inline int lowbit(int x){return x&(-x);}
inline void add(int x,int y,int k){
	while(x<=n){
		int p=y;
		while(p<=n){
			tr[x][p]+=k;
			p+=lowbit(p);
		} 
		x+=lowbit(x);
	}
}inline ll qry(int x,int y){
	ll res=0;
	while(x){
		int p=y;
		while(p){
			res+=tr[x][p];
			p-=lowbit(p);
		} 
		x-=lowbit(x);
	}return res;
	
}
signed main(){
	freopen("fire.in","r",stdin);
	freopen("fire.out","w",stdout);
	// ios::sync_with_stdio(false);
	// cin.tie(0); cout.tie(0);
	n=read(),Q=read();
	while(Q--){
		int op=read();
		if(op==1){
			int oo=read(),I=read(),opt=read(),x=read();x%=Mod;
			if(oo==0){
				int i=I;
				For(j,1,n){
					add(i,j,-a[i][j]);
					if(opt==1)a[i][j]&=x;
					if(opt==2)a[i][j]|=x;
					if(opt==3)a[i][j]^=x;
					if(opt==4)Add(a[i][j],x);
					add(i,j,a[i][j]);
				}
			}else{
				int j=I;
				For(i,1,n){
					add(i,j,-a[i][j]);
					if(opt==1)a[i][j]&=x;
					if(opt==2)a[i][j]|=x;
					if(opt==3)a[i][j]^=x;
					if(opt==4)Add(a[i][j],x);
					add(i,j,a[i][j]);
				}
				
			}
		}else{
			int x=read(),y=read();
			printf("%lld\n",qry(x,y));
//			puts("1");
		}
//		For(i,1,n){
//			For(j,1,n) printf("%lld ",a[i][j]);puts("");
//		}
	}
#ifdef LOCAL
    Debug("\nMy Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
#endif
	return 0;
}

